layui.use(['form','layer','element','laydate','laytpl'], function () {
     var laydate = layui.laydate,laytpl = layui.laytpl ,form = layui.form;
    $("#name").val(localStorage.getItem('name'));
    $("#headPic").attr("src",localStorage.getItem('headimgurl'));
    $("#crtName").val(localStorage.getItem('crtName'));

    form.on('submit(sendCode)', function(data){
         $.ajax({
             url: '/user/sendText?phone='+$("#phone").val(),
             type: 'get',
             success: function (data) {
                 var layerTips = parent.layer === undefined ? layui.layer : parent.layer;
                 if(data.rel){
                    layerTips.msg('发送成功');
                 }else{
                   layerTips.msg(data.msg);
                 }
             }
           });

        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
      });
    form.on('submit(save)', function(data){
        submitForm(data);
       return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
     });

     form.on('submit(cancel)', function(data){
         layer.confirm('确定重置吗？', null, function (index) {
           $('.layui-form')[0].reset();
            layer.close(index);
         });

        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
      });
});

function submitForm(data){
  $.ajax({
     url: '/user/register',
     type: 'post',
     data: data.field,
     dataType: "json",
     success: function (data) {
         var layerTips = parent.layer === undefined ? layui.layer : parent.layer;
         if(data.rel){
            layerTips.msg('保存成功');
            location="login";
         }else{
           layerTips.msg(data.msg);
         }
     }
   });
}

function setLabelValues(data) {
    for (var p in data) {
        $("#" + p + "").html(data[p]);
    }
}